package stu.day33_day38.day34;

import java.util.HashMap;
import java.util.Scanner;

public class hw4 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        char ch = sc.nextLine().charAt(0);
        String str = sc.nextLine();

        int left = 0;
        int max = 0;
        HashMap<Character,Integer> map = new HashMap<>();
        for(int i=0;i<str.length();i++){
            if(str.charAt(i)==ch){
                left = i+1;
                map.clear();
            }
            while(!del(map)){
                int num = map.get(str.charAt(left));
                num -= 1;
                if(num==0){
                    map.remove(str.charAt(left));
                }else {
                    map.put(str.charAt(left),num);
                }
                left += 1;
            }

            max = Math.max(max,i-left+1);

        }
        System.out.println(max);
    }

    public static boolean del(HashMap<Character,Integer> map){
        for (Character ch:map.keySet()){
            if(map.get(ch)>2){
                return false;
            }
        }
        return true;
    }


}
